#########################################################################
# File Name: debug.sh
# Author: libz
# mail: libingzhi2011@163.com
# Created Time: 2019年06月16日 15:35:26
#########################################################################
#!/usr/bin/env bash

OsIsCentos=0
OsIsUbuntu=0
OsIsCygwin=0
OsVersion=0

export OsIsCentos
export OsIsUbuntu
export OsIsCygwin
export OsVersion

#package mananger: yum,apt,eg.
PackMan=""

is_this_os(){
	return $(echo $(cat /etc/issue /etc/redhat-release /proc/version 2>/dev/null || \
lsb_release -a 2>/dev/null || uname -a) | grep -c -i $1)
	#return $(echo $(cat /proc/version 2>/dev/null || uname -a) | grep -c -i $1)
}

is_centos(){
	is_this_os "centos"
    echo $?
}

is_cygwin(){
	is_this_os "cygwin"
    echo $?
}

is_ubuntu(){
	is_this_os "ubuntu"
    echo $?
}

get_os_version(){
    echo $(echo $(cat /etc/issue /etc/redhat-release /proc/version 2>/dev/null || \
         lsb_release -a 2>/dev/null || uname -a) | grep -i -o "$1[' ']*[0-9]*" | grep -o [0-9]* |sort |uniq)
}

init_env(){
    if [[ $(is_centos) -ne 0 ]]; then
		echo os is centos
        OsIsCentos=1
        OsVersion=$(get_os_version "centos")
        PackMan=yum
	elif [[ $(is_cygwin) -ne 0 ]]; then
		echo os is cygwin
        OsIsCygwin=1
        OsVersion=$(get_os_version "cygwin")
        PackMan=apt-cyg
    elif [[ $(is_ubuntu) -ne 0 ]]; then
        echo os is ubuntu
        OsIsUbuntu=1
        OsVersion=$(get_os_version "ubuntu")
        PackMan=apt
	else
		echo unknown os
	fi
}

init_env
echo os version:$OsVersion
